package org.student.impl;

import java.util.List;

import org.springframework.stereotype.Component;
import org.student.dao.IStudentInfoDao;
import org.student.entity.StuSys_Score;
import org.student.entity.StuSys_Student;

@Component("StudentInfoDaoImpl")
public class StudentInfoDaoImpl extends HibernateDaoImpl implements
		IStudentInfoDao {

	@Override
	public void studentInfoSave(StuSys_Student studentInfo) throws Exception {
		super.save(studentInfo);
	}

	@Override
	public List<StuSys_Student> getAllStudent() throws Exception {
		return (List<StuSys_Student>) super.getHibernateTemplate().find(
				"from StuSys_Student");
	}

	@Override
	public List<StuSys_Student> getStudentsById(String id) throws Exception {
		return (List<StuSys_Student>) super.getHibernateTemplate().find(
				"from StuSys_Student where id = " + id);
	}

	@Override
	public List<StuSys_Student> getStudentsByClass(String className)
			throws Exception {
		return (List<StuSys_Student>) super.getHibernateTemplate().find(
				"from StuSys_Student where classInfo.className = '" + className
						+ "'");
	}

	@Override
	public List<StuSys_Student> getStudentsByInsititue(String insititueName)
			throws Exception {
		return (List<StuSys_Student>) super.getHibernateTemplate().find(
				"from StuSys_Student where classInfo.insititueName = '"
						+ insititueName + "'");
	}

	@Override
	public List<StuSys_Student> getStudentsByName(String name) throws Exception {
		return (List<StuSys_Student>) super.getHibernateTemplate().find(
				"from StuSys_Student where stuName = '" + name + "'");
	}

	@Override
	public List<StuSys_Student> getStudentsByWords(String words)
			throws Exception {
		return (List<StuSys_Student>) super.getHibernateTemplate().find(
				"from StuSys_Student where stuName like '%" + words
						+ "%' or birth_date like '%" + words
						+ "%' or create_date like '%" + words
						+ "%' or sex like '%" + words + "%' or tel like '%"
						+ words + "%' or address like '%" + words
						+ "%' or memo like '%" + words
						+ "%' or classInfo.className like '%" + words
						+ "%' or classInfo.manager like '%" + words
						+ "%' or classInfo.specialtyName like '%" + words
						+ "%' or classInfo.insititueName like '%" + words
						+ "%' or classInfo.memo like '%" + words + "%' ");
	}

	@Override
	public void updateStudent(StuSys_Student student) throws Exception {
		super.update(student);
	}

	@Override
	public void deleteStudentById(int id) throws Exception {
		super.delete(StuSys_Student.class, id);
	}

	@Override
	public StuSys_Student getStudentInfoById(int id) throws Exception {
		return (StuSys_Student) super.get(StuSys_Student.class, id);
	}

	@Override
	public void deleteScore(int id) throws Exception {
		this.delete(StuSys_Score.class, id) ;
	}
}
